 /**
 * @file tkl_reporting.h
 * @brief Common process - reporting
 * @version 1.0.0
 * @date 2021-08-09
 *
 * @copyright Copyright 2021-2022 Tuya Inc. All Rights Reserved.
 *
 */

#ifndef __TKL_REPORTING_H__
#define __TKL_REPORTING_H__


#ifdef __cplusplus
    extern "C" {
#endif

#include "tuya_cloud_types.h"
#include "tuya_zigbee_stack.h"


/**
 * @enum the direction of the reporting table
 */
typedef enum {
    TKL_REPORT_DIRECTION_REPORTED = 0x00,   ///< The direction of active reporting
    TKL_REPORT_DIRECTION_RECEIVED = 0x01,   ///< The direction of receiving data
} TKL_REPORT_DIREC_E;


/**
 * @enum reporting table structure
 */
typedef struct {
    TKL_REPORT_DIREC_E direction;   ///< reporting direction
    UINT8_T  ep_id;                 ///< endpoint id
    UINT16_T cluster_id;            ///< cluster id, see ZG_CLUSTER_ID_E
    UINT16_T attr_id;               ///< attribute id
    ZG_CLUSTER_MASK_E mask;         ///< reporting cluster mask
    UINT16_T manuf_code;            ///< manufacture code default 0
    union {
        struct {
            UINT16_T min_interval;  ///< mini reporting interval, measured in seconds
            UINT16_T max_interval;  ///< max reporting interval, measured in seconds
            UINT32_T report_change; ///< mini change to the attribute that will result in a report being sent
        } reported;
        struct {
            UINT16_T source_addr;   ///< node id of the source of the received reports
            UINT8_T  endpoint;      ///< remote endpoint from which the attribute is reported
            UINT16_T timeout;       ///< max expected time between reports, measured in seconds
        } received;
    } data;
} TKL_REPORT_TABLE_T;

typedef VOID_T (*TKL_RECOVERY_CB_T)(OPERATE_RET result);

/**
 * @brief zigbee reporting init and register reporting table
 *
 * @param[in]   entery: reporting table list
 * @param[in]   sums:   reporting table number
 * @return  OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tkl_zg_reporting_init(TKL_REPORT_TABLE_T *entery, UINT8_T sums);

/**
 * @brief add reporting entry to report table
 *
 * @param[in]   entery: reporting table entery
 * @return  TRUE on success. FALSE on error
 */
BOOL_T tkl_zg_add_reporting_entry(TKL_REPORT_TABLE_T *entery);

/**
 * @brief clear reporting table
 *
 * @param[in] none
 * @return  none
 */
VOID_T tkl_zg_clear_reporting_table(VOID_T);

/**
 * @brief load the default binding table registered during initialization
 *
 * @param[in] none
 * @return  none
 */
VOID_T tkl_zg_load_default_reporting_table(VOID_T);

/**
 * @brief 
 * 
 * @param func 
 * @return VOID_T 
 */
VOID_T tkl_zg_reporting_table_recovery_init(TKL_RECOVERY_CB_T func);
#ifdef __cplusplus
}
#endif

#endif

